package com.zbhk.qc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zbhk.qc.dto.ArticleVO;
import com.zbhk.qc.entity.VdPublicArticle;
import com.zbhk.qc.mapper.VdPublicArticleMapper;
import com.zbhk.qc.service.ArticleServer;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhulenan on 2020/7/22 11:14
 */
@Service
public class ArticleServerImpl implements ArticleServer {

    @Autowired
    private VdPublicArticleMapper vdPublicArticleMapper;


    @Override
    public IPage<VdPublicArticle> getArticleList(String name, Integer pageSize, Integer pageNumber) {
        IPage<VdPublicArticle> page = new Page<>(pageNumber,pageSize);

        List<VdPublicArticle> list = vdPublicArticleMapper.getArticleList(name,page);
        page.setRecords(list);
        return page;
    }

    @Override
    public void save(ArticleVO articleVO) {
        VdPublicArticle vdPublicArticle = new VdPublicArticle();
        BeanUtils.copyProperties(articleVO,vdPublicArticle);
        vdPublicArticleMapper.insert(vdPublicArticle);
    }

    @Override
    public VdPublicArticle update(ArticleVO articleVO) {
        VdPublicArticle vdPublicArticle = vdPublicArticleMapper.selectById(articleVO.getId());
        BeanUtils.copyProperties(articleVO,vdPublicArticle);
        vdPublicArticleMapper.updateById(vdPublicArticle);
        return vdPublicArticle;
    }

    @Override
    public void delete(Long id) {
        vdPublicArticleMapper.deleteById(id);
    }

    @Override
    public VdPublicArticle get(Long id) {
        VdPublicArticle vdPublicArticle = vdPublicArticleMapper.selectById(id);
        return vdPublicArticle;
    }
}

  